﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using ClassLibrary1;
namespace Bilyteam_Website.Admin
{
    public partial class Contacts : System.Web.UI.Page
    {
        SqlConnection conn = new SqlConnection();
        SqlCommand cmd = new SqlCommand();
        SqlDataAdapter da = new SqlDataAdapter();
        DataSet ds = new DataSet();
        binContacts bin = new binContacts();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                bindata();

            }


        }
       
        private void bindata()
        {
            //conn.ConnectionString = ConfigurationManager.ConnectionStrings["PROJECT"].ConnectionString;
            //cmd.Connection = conn;
            //cmd.CommandText = "select * from Contacts";
            
            //cmd.CommandType = CommandType.Text;
            //da.SelectCommand = cmd;
            
            //da.Fill(ds, "Contatcs");
           DataTable list = bin.getContacts();
           gvContacts.DataSource = list;
            gvContacts.DataBind();
            
         
           
        }

        protected void gvContacts_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

       

      

       

        private void load_data()
        {
          
        }

        

       





        public string ContacID { get; set; }

        public SqlConnection con { get; set; }

        

      

       

        protected void gvContacts_RowUpdating2(object sender, GridViewUpdateEventArgs e)
        {
            //int id = int.Parse(gvContacts.DataKeys[e.RowIndex].Value.ToString());
            //string ID = (gvContacts.Rows[e.RowIndex].Cells[1].Controls[0] as TextBox).Text;
            //string IDBoPhan = (gvContacts.Rows[e.RowIndex].Cells[2].Controls[0] as TextBox).Text;
            //string IDTThanh = (gvContacts.Rows[e.RowIndex].Cells[2].Controls[0] as TextBox).Text;
            //string hovaten = (gvContacts.Rows[e.RowIndex].Cells[4].Controls[0] as TextBox).Text;
            //string gioitinh = (gvContacts.Rows[e.RowIndex].Cells[4].Controls[0] as TextBox).Text;
            //string TenCty = (gvContacts.Rows[e.RowIndex].Cells[5].Controls[0] as TextBox).Text;
            //string chucvu = (gvContacts.Rows[e.RowIndex].Cells[5].Controls[0] as TextBox).Text;
            //string diachi = (gvContacts.Rows[e.RowIndex].Cells[5].Controls[0] as TextBox).Text;
            //string sdt = (gvContacts.Rows[e.RowIndex].Cells[5].Controls[0] as TextBox).Text;
            //string email = (gvContacts.Rows[e.RowIndex].Cells[5].Controls[0] as TextBox).Text;
            //string website = (gvContacts.Rows[e.RowIndex].Cells[5].Controls[0] as TextBox).Text;
            //string noidung = (gvContacts.Rows[e.RowIndex].Cells[6].Controls[0] as TextBox).Text;
            //conn.ConnectionString = ConfigurationManager.ConnectionStrings["PROJECT"].ConnectionString;
            //SqlCommand cmd = new SqlCommand("update Contacts set IDTeam='" + IDBoPhan + "',IDProvices='" + IDTThanh + "', FullName='" + hovaten + "',Gender='" + gioitinh + "',CompanyName='" + TenCty + "',Position='" + chucvu + "',Address='" + diachi + "',Telephone='" + sdt + "',Email='" + email + "',Website='" + website + "',MainContent='" + noidung + "' where masv='" + id + "'", con);
            //con.Open();
            //cmd.ExecuteNonQuery();
            //con.Close();
            //gvContacts.EditIndex = -1;
            //load_data();
            binContacts bin = new binContacts();
            
        }

        protected void gvContacts_RowEditing1(object sender, GridViewEditEventArgs e)
        {
            //gvContacts.EditIndex = e.NewEditIndex;
            //load_data();
        }

        protected void gvContacts_RowDeleting1(object sender, GridViewDeleteEventArgs e)
        {
            //int id = int.Parse(gvContacts.DataKeys[e.RowIndex].Value.ToString());
            //conn.ConnectionString = ConfigurationManager.ConnectionStrings["PROJECT"].ConnectionString;

            //SqlCommand cmd = new SqlCommand("delete from Contacts where ContactID='" + id + "'", con);
            //con.Open();
            //cmd.ExecuteNonQuery();
            //con.Close();
            //load_data();
        }

        protected void gvContacts_RowCancelingEdit1(object sender, GridViewCancelEditEventArgs e)
        {
            //gvContacts.EditIndex = -1;
            //load_data();
        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void gvContacts_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvContacts.PageIndex = e.NewPageIndex;
            DataTable list = bin.getContacts();
            gvContacts.DataSource = list;
            gvContacts.DataBind();
        }

       

       
    }
}